package org.maggioni.springsandbox.rehearsals.e05aop.e01basic.services;

import org.maggioni.springsandbox.rehearsals.e05aop.e01basic.annotations.Loggable;
import org.maggioni.springsandbox.rehearsals.e05aop.e01basic.model.BusinessObject;

public class BusinessService {
	
	private BusinessObject businessObject;

	public void setBusinessObject(BusinessObject businessObject) {
		this.businessObject = businessObject;
	}
	public BusinessObject getBusinessObject() {
		System.out.println("BusinessService.getBusinessObject() called!");
		return businessObject;
	}
	
	public BusinessObject doThrow(boolean doThrow) {
		if (doThrow) {
			throw new RuntimeException();
		}
		BusinessObject bo = new BusinessObject();
		bo.setField1("I haven't thrown any exception");
		return bo;
	}
	
	@Loggable
	public BusinessObject doThrow() {
		return doThrow(true);
	}

	public BusinessObject doThrowForAroundAdvice(boolean doThrow) {
		if (doThrow) {
			throw new RuntimeException();
		}
		BusinessObject bo = new BusinessObject();
		bo.setField1("I haven't thrown any exception");
		return bo;
	}
	
	public BusinessObject doThrowForAroundAdvice() {
		return doThrowForAroundAdvice(true);
	}
	

}
